package org.springbus.habit.web.response;

import lombok.Data;
import org.springbus.habit.emus.ResponseCode;
import java.util.List;

@Data
public class PageResponse<T> {

    private Long code;
    private String message;
    private Page<T> data;
    private Boolean success;

    private void isSuccess() {
        this.success = Long.valueOf(ResponseCode.SUCCESS.getCode()).equals(code);
    }

    public PageResponse(ResponseCode responseCode) {
        this.code = Long.valueOf(responseCode.getCode());
        this.message = responseCode.getDesc();
        this.data = new Page<>();
        isSuccess();
    }


    public PageResponse(List<T> data, long total) {
        this.code = Long.valueOf(ResponseCode.SUCCESS.getCode());
        this.message = ResponseCode.SUCCESS.getDesc();
        Page<T> page = new Page<>();
        page.setItems(data);
        page.setTotal(total);
        this.data = page;
        isSuccess();
    }

    public PageResponse(String responseCode, String responseDesc) {
        this.code = Long.valueOf(responseCode);
        this.message = responseDesc;
        this.data = new Page<>();
        isSuccess();
    }

    public PageResponse(String responseCode, String responseDesc,List<T> data, long total) {
        this.code = Long.valueOf(responseCode);
        this.message = responseDesc;
        this.data = new Page<>();
        this.data.setItems(data);
        this.data.setTotal(total);
        isSuccess();
    }
}
